package com.briup.corejava.day05;

/**
 * 数组的基本操作
 * 1、声明
 * 2、初始化
 * 3、下标和长度
 * 4、赋值取值
 * 5、遍历
 */
public class Test1 {
    // 定义一个数组输出的方法
    public static void arrayPrint(int[] arr){
        System.out.print("[");
        for(int i=0;i<arr.length;i++){
            if(i != arr.length-1)
                System.out.print(arr[i]+", ");
            else
                System.out.print(arr[i]+"]");
        }
        System.out.println();
    }
    public static void arrayPrint(String[] arr){
        System.out.print("[");
        for(int i=0;i<arr.length;i++){
            if(i != arr.length-1)
                System.out.print(arr[i]+", ");
            else
                System.out.print(arr[i]+"]");
        }
        System.out.println();
    }
    public static void main(String[] args) {
        // 声明+初始化
        int[] arr1;
        arr1 = new int[3];
        double[] arr2 = new double[]{1,31,4,52,0.03,20};
        String[] strs = {"C","Java","Python","C++","C#"};
        // 取值赋值
        System.out.println(arr2.length);
        System.out.println(arr2[0]);
        arr1[0] = 100;
        System.out.println(arr2);
        // 遍历
        System.out.print("[");
        for(int i=0;i<strs.length;i++){
            if(i != strs.length-1)
                System.out.print(strs[i]+", ");
            else
                System.out.print(strs[i]+"]");
        }
        System.out.println();
        // 调用数组的输出方法，使用方法重载会参考实参的类型自动识别调用哪个实现
        arrayPrint(arr1);
        // arrayPrint(arr2); // 因为没有定义double[]的参数
        arrayPrint(strs);
    }
}
